package ysq.xyg.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import tk.mybatis.mapper.entity.Example;
import ysq.xyg.dao.WebItemDao;
import ysq.xyg.model.WebItem;
import ysq.xyg.service.WebItemService;

import javax.annotation.Resource;
import java.util.List;

/**
 * 药品
 *
 */
@Service("webItemService")
public class WebItemServiceImpl extends BaseServiceImpl<WebItem> implements WebItemService {

    @Resource
    private WebItemDao webItemDao;
    @Autowired
    public void setpictureDao(WebItemDao webItemDao) {
        this.baseDao = webItemDao;
    }

    @Override
    public PageInfo<WebItem> pageInfo(WebItem webItem, int pageSize, int pageNum) {
        PageHelper.startPage(pageNum, pageSize);
        PageHelper.orderBy(" sort asc");
        // 通用Example查询
        Example example = new Example(WebItem.class);
        Example.Criteria criteria = example.createCriteria();
        if (StringUtils.isNotEmpty(webItem.getType())) {
            criteria.andEqualTo("type", webItem.getType());
        }
        if (StringUtils.isNotEmpty(webItem.getName())) {
            criteria.andLike("name","%"+ webItem.getName()+"%");
        }
        List<WebItem> list = webItemDao.selectByExample(example);
        return new PageInfo<WebItem>(list);
    }

    @Override
    public List<WebItem> list(WebItem webItem) {
        // 通用Example查询
        Example example = new Example(WebItem.class);
        Example.Criteria criteria = example.createCriteria();
        if (StringUtils.isNotEmpty(webItem.getType())) {
            criteria.andEqualTo("type", webItem.getType());
        }
        if (StringUtils.isNotEmpty(webItem.getName())) {
            criteria.andLike("name","%"+ webItem.getName()+"%");
        }
        example.setOrderByClause(" sort asc");
        List<WebItem> list = webItemDao.selectByExample(example);
        return list;
    }
}
